import { Base } from '../../utils/base.js';

class Order extends Base {
    constructor() {
        super()
    }
    //获取订单
    getOrder(params, callback) {
        let url = '/ddaigo-platform/order/list'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //取消订单
    cancelOrder(params, callback) {
        let url = '/ddaigo-platform/order/cancel';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //退款
    wxRefund(params, callback) {
        // let url = "/ddaigo-platform/refund/refund";
        let url = "/ddaigo-platform/refund/refundAudit";
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //删除订单
    deleteOrder(params, callback) {
        let url = '/ddaigo-platform/order/delete'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    // 获取不同订单数量
    getOrderCount(params,callback){
        let url = '/ddaigo-platform/order/getOrderCount'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //付款
    wxPay(params, callback) {
        let url = "/ddaigo-platform/pay/doUnifiedOrder";
        var reType = 'POST';        
        this.commonRequest(url, reType, params, callback);
    } 
    // 根据id获取单个地址
    getUserAddressById(params, callback) {
        var url = '/ddaigo-platform/user/getUserAddressById';
        var reType = 'POST';
        this.commonRequest(url, reType,params, callback);
    }
    // 减库存接口
    reduceGoodsStock(params,callback){
        var url = '/ddaigo-platform/order/reduceGoodsStock'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //   会员支付
    doUnifiedOrderForRechargeMember(params, callback) {
        let url = '/ddaigo-platform/pay/doUnifiedOrderForRechargeMember'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    commonRequest(url, reType, params, callback) {
        var that = this;
        var param = {
            url: url,
            type: reType,
            data: params,
            sCallback: function (data) {
                typeof callback == 'function' && callback(data);
            },
            eCallback: data => {
                callback && callback({ status: false,data: data });
            }
        };
        this.request(param);
    }
    conutdown(endtime) {
            var date = new Date();
            var end = new Date(endtime);
            var _time = end - date;
            if (_time <= 0 || !endtime) return '00:00'
            var d = Math.floor(_time / 1000 / 60 / 60 / 24);
            var h = Math.floor(_time / 1000 / 60 / 60 % 24);
            var m = Math.floor(_time / 1000 / 60 % 60);
            var s = Math.floor(_time / 1000 % 60);
            var ms = Math.floor(_time % 1000);
            if (m < 10) m = '0' + m
            if(s < 10) s = '0' + s
            return m +':'+ s
            // console.log(`${d}天${h}小时${m}分${s}秒${ms}`)
    }
    formate(fmt, data){
        var data = data ? data : 'yyyy-MM-dd hh:mm:ss'
        return (new Date(fmt)).cartFormat(data)
    }
}
module.exports = {
    Order
}